package com.jeecms.edu.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeecms.common.web.ResponseUtils;
import com.jeecms.edu.entity.SchoolInformation;

import net.sf.json.JSONObject;


/**
 * 学校详情页面
 */
@WebServlet("/SchoolSchoolDeatil")
public class SchoolSchoolDeatil extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		Object detail=request.getSession().getServletContext().getAttribute("schooldetail");
		String enrollment=(String)request.getSession().getServletContext().getAttribute("enrollment");
		String schoolurl=(String)request.getSession().getServletContext().getAttribute("schoolurl");
		List hotlist=SchoolInformation.AllHotSchoolList();
		System.out.println(detail);
		JSONObject jsonObject=new JSONObject();
		//热门学校
		String hotresult="";		//热门学校集合
		int hotsize=hotlist.size();	
		if (hotlist.size()>5) {   //增加显示数量限制
			hotsize=5;
		}
		for (int i = 0; i < hotsize; i++) {
			Map map=(Map) hotlist.get(i);
			String school=(String) map.get("schoolname");
			String changes="javascript:gotoDetail('"+school+"');";
			hotresult+="<div class='hot_thread'><a href="+changes+"><img src='"+map.get("schoolimgurl")+"' class='hot_pic' /></a>"
					+"<p>"+map.get("schoolname")+"</p><p>"+map.get("region")+"</p><p>"+map.get("schoolnature")+"</p></div>";
		}
		if (null!=enrollment) {
			jsonObject.put("enrollment",enrollment);
		}else{
			jsonObject.put("enrollment", "");
		}
		if (null!=schoolurl) {
			jsonObject.put("schoolurl",schoolurl);
		}else{
			jsonObject.put("schoolurl", "");
		}
		jsonObject.put("hotschool", hotresult);		
		JSONObject json=JSONObject.fromObject(detail);
		jsonObject.put("shdetail", json.toString());
		ResponseUtils.renderJson(response, jsonObject.toString()); 
	}

}
